package com.matt.controller.web;

import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.exception.BusinessException;
import com.matt.commons.model.StatusResponse;
import com.matt.domain.rel.RelAreaLiveRecord;
import com.matt.foundation.dto.AreaSettingDTO;
import com.matt.foundation.model.ErrorCode;
import com.matt.foundation.model.MemVerificationCache;
import com.matt.repository.RelAreaLiveRecordRepository;
import com.matt.service.remoteCall.DTO.AreaListDTO;
import com.matt.service.remoteCall.SsoCallService;
import io.swagger.annotations.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

import static com.matt.foundation.constant.RequestConstant.TICKET;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/8/1
 * *******************************
 */
@RestController
@RequestMapping("/web/area_live")
@Api(tags ="WEB - 园区摄像头配置")

public class WebAreaLiveController {
    @Autowired
    private SsoCallService ssoCallService;

    @Autowired
    private RelAreaLiveRecordRepository relAreaLiveRecordRepository;

    private static final String LIVE_ROOM_SWITCH_KEY = "LIVE_ROOM_SWITCH_KEY";
    @ApiOperation(value = "WEB 获取园区配置",httpMethod = "POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
    })
    @ApiResponses({
  		@ApiResponse(code = 000000, message = "成功"),
  		@ApiResponse(code = 000001, message = "ticket已过期")
  	})
    @RequestMapping("/get")
    public StatusResponse get(@RequestHeader(TICKET) String ticket) {
        StaffDTO staffDTO = ssoCallService.getStaffDTO(ticket);
        AreaSettingDTO relAreaLiveRecord = ssoCallService.getAreaSetting(LIVE_ROOM_SWITCH_KEY, staffDTO.getAreaId());
        return StatusResponse.success(relAreaLiveRecord);
    }


    @ApiOperation(value = "WEB 配置园区签到开启、关闭摄像头",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code = 000000, message = "成功"),
            @ApiResponse(code = 000001, message = "ticket已过期")
    })
    @RequestMapping("/add")
    public StatusResponse add(@RequestHeader(TICKET) String ticket,String enabled) {
        StaffDTO staffDTO = ssoCallService.getStaffDTO(ticket);
        Boolean relAreaLiveRecord = ssoCallService.addAreaSetting(LIVE_ROOM_SWITCH_KEY, enabled + "", "园摄像头开关","",staffDTO.getAreaId());
        return StatusResponse.success(relAreaLiveRecord);
    }

}
